package com.hawthorn.mq.service.syslogoperation.impl;

import com.hawthorn.entity.po.SysLogOperationPO;
import com.hawthorn.mq.repository.SysLogOperationMapper;
import com.hawthorn.mq.service.syslogoperation.SysLogOperationService;
import com.hawthorn.platform.redis.RedisMyClient;
import com.hawthorn.platform.utils.common.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class SysLogOperationServiceImpl implements SysLogOperationService
{
  @Autowired
  private SysLogOperationMapper sysLogOperationMapper;
  @Autowired
  private RedisMyClient redisMyClient;

  @Override
  public void saveLogOperation(Map<String, Object> param)
  {
    String account = MyUtil.getValue(param.get("account"));

    SysLogOperationPO sysLogOperationPO = new SysLogOperationPO();
    Map<String, Object> msgData = (Map) param.get("msgData");

    // 获取redis中用户信息
    Map<String, Object> userInfo = redisMyClient.getUserInfo(account);

    sysLogOperationPO.setUserName(MyUtil.getValue(userInfo.get("userName")));
    sysLogOperationPO.setUserId(MyUtil.getValue(userInfo.get("id")));
    sysLogOperationPO.setUserDeptId(MyUtil.getValue(userInfo.get("deptId")));
    sysLogOperationPO.setOperateIp(MyUtil.getValue(msgData.get("ip")));
    sysLogOperationPO.setOperateDivision(MyUtil.getValue(msgData.get("cityInfo")));
    sysLogOperationPO.setBrowser(MyUtil.getValue(msgData.get("browser")));
    sysLogOperationPO.setExecMethod(MyUtil.getValue(msgData.get("methodName")));
    sysLogOperationPO.setExecParams(MyUtil.getValue(msgData.get("parameters")));
    sysLogOperationPO.setExecTime(MyUtil.getValue(msgData.get("execTime")));

    sysLogOperationPO.setResult(MyUtil.getValue(msgData.get("result")));
    sysLogOperationPO.setMemo(MyUtil.getValue(msgData.get("memo")));
    sysLogOperationPO.setOperateType(MyUtil.getValue(msgData.get("op")));

    sysLogOperationPO.setCreateBy(account);
    sysLogOperationPO.setLastUpdateBy(account);

    sysLogOperationMapper.save(sysLogOperationPO);
  }
}
